<template>
  <div class="member-account">
    <div class="account-block">
      <h4>安全设置</h4>
    </div>
    <div class="account-block2">
      <div class="icon">
        <span class="iconfont icon-suo"></span>
      </div>
      <div class="text">
        <p>登录密码</p>
        <p>建议您定期更换密码，设置安全性高的密码可以使帐号更安全</p>
      </div>
      <a href="javascript:;" class="btn" @click="openPswDialog">更换</a>
    </div>
    <div class="account-block2">
      <div class="icon">
        <span class="iconfont icon-phone"></span>
      </div>
      <div class="text">
        <p>绑定手机</p>
        <p>安全手机可以用于登录帐号，重置密码或其他安全验证</p>
      </div>
      <RouterLink to="/member/account/update-mobile" href="javascript:;" class="btn">立即绑定</RouterLink>
    </div>
  </div>
  <!-- 打开更新密码组件 -->
  <UpdatePsw ref="pswUpdateCom" @on-update="updateHandler" />
</template>

<script>
import { computed, ref } from 'vue'
import UpdatePsw from './components/update-psw.vue'
import { useStore } from 'vuex'
import Message from '@/components/library/message'
export default {
  name: 'MemberAccount',
  components: {
    UpdatePsw
  },
  setup () {
    // 获取用户的登录信息后使用
    const store = useStore()
    // 使用vuex中的state需要设置计算属性
    const profile = computed(() => {
      return store.state.user.profile
    })
    // 打开添加编辑收货地址组件
    const pswUpdateCom = ref(null)
    const openPswDialog = () => {
      pswUpdateCom.value.open()
    }
    const updateHandler = (formData) => {
      console.log(formData.newPsw)
      Message({ type: 'error', text: '密码更新失败，请稍后再试' })
    }
    return { profile, openPswDialog, pswUpdateCom, updateHandler }
  }
}
</script>

<style lang="less" scoped>
.member-account {
  height: 100%;
  background: #fff;
  padding: 0 20px;
  .account-block {
    height: 66px;
    border-bottom: 1px solid #e8e8e8;
    padding: 25px 0 20px 0;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin: 0 30px;
    h4 {
      font-size: 16px;
      font-weight: normal;
    }
  }
  .account-block2 {
    display: flex;
    height: 124px;
    align-items: center;
    border-bottom: 1px dashed #f5f5f5;
    margin-top: 20px;
    .icon {
      width: 90px;
      text-align: center;
      .iconfont {
        font-size: 32px;
        color: #27ba9b;
      }
    }
    .text {
      flex: 1;
      line-height: 30px;
      p:first-child {
        font-size: 16px;
      }
      p:last-child {
        color: #999;
      }
    }
    .iconfont {
      font-size: 32px;
      color: #27ba9b;
    }
    .btn {
      width: 160px;
      height: 50px;
      margin-right: 30px;
      background: #27ba9b;
      color: #fff;
      border-radius: 4px;
      font-size: 16px;
      text-align: center;
      line-height: 50px;
    }
  }
}
</style>
